package com.ruoyi.admin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.admin.domain.CorpCompanyDepartments;
import com.ruoyi.admin.service.ICorpCompanyDepartmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 部门列表Controller
 * 
 * @author Jimmy
 * @date 2022-08-04
 */
@RestController
@RequestMapping("/admin/corp_company_departments")
public class CorpCompanyDepartmentsController extends BaseController
{
    @Autowired
    private ICorpCompanyDepartmentsService corpCompanyDepartmentsService;

    /**
     * 查询部门列表列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:list')")
    @GetMapping("/list")
    public TableDataInfo list(CorpCompanyDepartments corpCompanyDepartments)
    {
        startPage();
        List<CorpCompanyDepartments> list = corpCompanyDepartmentsService.selectCorpCompanyDepartmentsList(corpCompanyDepartments);
        return getDataTable(list);
    }

    /**
     * 导出部门列表列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:export')")
    @Log(title = "部门列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CorpCompanyDepartments corpCompanyDepartments)
    {
        List<CorpCompanyDepartments> list = corpCompanyDepartmentsService.selectCorpCompanyDepartmentsList(corpCompanyDepartments);
        ExcelUtil<CorpCompanyDepartments> util = new ExcelUtil<CorpCompanyDepartments>(CorpCompanyDepartments.class);
        util.exportExcel(response, list, "部门列表数据");
    }

    /**
     * 获取部门列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(corpCompanyDepartmentsService.selectCorpCompanyDepartmentsById(id));
    }

    /**
     * 新增部门列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:add')")
    @Log(title = "部门列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CorpCompanyDepartments corpCompanyDepartments)
    {
        return toAjax(corpCompanyDepartmentsService.insertCorpCompanyDepartments(corpCompanyDepartments));
    }

    /**
     * 修改部门列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:edit')")
    @Log(title = "部门列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CorpCompanyDepartments corpCompanyDepartments)
    {
        return toAjax(corpCompanyDepartmentsService.updateCorpCompanyDepartments(corpCompanyDepartments));
    }

    /**
     * 删除部门列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_departments:remove')")
    @Log(title = "部门列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(corpCompanyDepartmentsService.deleteCorpCompanyDepartmentsByIds(ids));
    }
}
